<template>
	<div class="page-wrap">
		<div class="page-inner">
			<div class="page-table-ctx-wrap">
				<!-- 控制器 -->
				<div class="actions-box">
					<div class="control-box">
						<div class="control-left">
							<div class="control-item">
								<!-- <el-button type="primary" @click="doAdd()">
									添加
								</el-button> -->
							</div>
						</div>
						<div class="control-right">
							<!-- <div class="action-item">
								<el-date-picker v-model="time_range" type="daterange" align="right" unlink-panels range-separator="至"
									start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
									:picker-options="pickerOptions">
								</el-date-picker>
							</div> -->
							<div class="action-item">
								<el-select clearable="" v-model="searchParams.refundStatus" placeholder="类型筛选"
									@change="select_refundStatus_onchange">
									<el-option v-for="item in refundStatus_select_options" :key="item.value"
										:label="item.title" :value="item.value">
									</el-option>
								</el-select>
							</div>
							<div class="action-item">
								<el-input clearable="" v-model="searchParams.keyword" placeholder="请输入关键词">
									<el-button slot="append" size="small" icon="el-icon-search" @click="doSearch()">
									</el-button>
								</el-input>
							</div>
						</div>
					</div>
				</div>
				<!-- 控制器 -->

				<div class="tab-box">
					<el-tabs type="card" v-model="searchParams.type" @tab-click="tabClick">
						<el-tab-pane v-for="(item, index) in tabList" :label="item.title" :name="item.value">

						</el-tab-pane>
					</el-tabs>
				</div>

				<!-- 渲染表格 -->
				<div class="table-view">
					<w_table ref="w_table" @emitTable="emitTable" />
				</div>
				<!-- 渲染表格 -->
				<div class="table-util">
					<div class="util-left">
						<!-- 批量选择 -->
					</div>
					<div class="util-right">
						<div class="pagi-item">
							<w_pagination v-if="tableData.length" :total="total" :pagination="pagination"
								@size-change="onSizeChange" @current-change="onCurrentChange" />
						</div>
					</div>
				</div>
			</div>
		</div>

		<refund_service_detail_modal data-title="售后详情" ref="refund_service_detail_modal"
			@confirm="confirmAuditSubmit" />
		<refund_audit_modal data-title="售后审核" ref="refund_audit_modal" @confirm="confirmAuditSubmit" />
		<refund_exchange_ship_modal data-title="换货-发货" ref="refund_exchange_ship_modal" @confirm="confirmAuditSubmit" />
	</div>
</template>

<script>
import refund_service_detail_modal from "@/components/refund/refund_service_detail_modal.vue";
import refund_audit_modal from "@/components/refund/refund_audit_modal.vue";
import refund_exchange_ship_modal from "@/components/refund/refund_exchange_ship_modal.vue";

import page_config from "@/constant/refund/refund-list.js";
import page_mixin from "@/mixins/page_mixin.js";
export default {
	name: "news-list",
	mixins: [page_mixin],
	components: {
		refund_service_detail_modal,
		refund_audit_modal,
		refund_exchange_ship_modal,
	},
	data() {
		return {
			page_config,


			// tabSelectValue: 1,
			tabList: [{
				value: 1,
				title: '退款',
			},
			{
				value: 2,
				title: '退货退款',
			},
			{
				value: 3,
				title: '换货',
			},
			],


			searchParams: {
				page: 1,
				pageNum: 10,
				type: 1, //退换货类型(1-退款 2-退货退款 3-换货)
				keyword: '',
				refundStatus: '', //状态：1-待审核 2-待买家发货 7-退货待发货 3-待退款 4-换货待发货 5-待客户收货 6-已完成 8-已取消
			},
			refundStatus_select_options: [{
				title: '全部状态',
				value: '',
			},
			{
				title: '待审核',
				value: 1,
			},
			{
				title: '待买家发货',
				value: 2,
			},
			{
				title: '待退款',
				value: 3,
			},
			{
				title: '换货待发货',
				value: 4,
			},
			{
				title: '待客户收货',
				value: 5,
			},
			{
				title: '已完成',
				value: 6,
			},
			{
				title: '退货待发货',
				value: 7,
			},
			],

			//
			time_range: [],

			pickerOptions: {
				disabledDate(time) {
					return time.getTime() > Date.now();
				},
				shortcuts: [{
					text: "最近一周",
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit("pick", [start, end]);
					},
				},
				{
					text: "最近一个月",
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
						picker.$emit("pick", [start, end]);
					},
				},
				{
					text: "最近三个月",
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
						picker.$emit("pick", [start, end]);
					},
				},
				],
			},
		};
	},
	computed: {

	},
	watch: {},
	created() {

	},
	mounted() {

	},
	methods: {
		tabClick(tab, event) {
			console.log(tab, event);

			this.pagination.page = 1;
			this.searchParams.refundStatus = ''
			this.setView()
		},
		format_list_data(list) {
			list.forEach(v => {
				let product = v.products || {};
				v.product_title = product.title
				v.product_keyVals = product.keyVals
				v.product_image = product.image
			})
		},

		doRowOther(row, action_title) {
			if (action_title == '详情') {
				// this.$refs.refund_service_detail_modal.init(row)
				this.toRoute({
					path: '/refund-detail',
					query: {
						id: row.id
					}
				})
			} else if (action_title == '审核') {
				this.$refs.refund_audit_modal.init(row)
			} else if (action_title == '退款完成') {
				this.do_finish_refund_money(row)
			} else if (action_title == '确认收货') {
				this.do_finish_refund_receive(row)
			} else if (action_title == '换货发货') {
				this.$refs.refund_exchange_ship_modal.init(row)
			}
		},

		do_finish_refund_money(row) {
			this.$confirm('确定退款完成?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.$api({
					url: '/admin_service.php',
					method: "get",
					data: {
						action: "refund_updateAfterSales",
						id: row.id,
						updateType: 4, //类型：1-审核驳回 2-审核通过 3-确认收货 4-完成退款
					},
				}).then((res) => {
					if (res.code == 200) {
						this.setView();
						this.$message({
							message: res.msg,
							type: 'success'
						})
					} else {
						alertErr(res.msg)
					}
				});
			}).catch(() => {

			});
		},

		do_finish_refund_receive(row) {
			this.$confirm('确认收货?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.$api({
					url: '/admin_service.php',
					method: "get",
					data: {
						action: "refund_updateAfterSales ",
						id: row.id,
						updateType: 3, //类型：1-审核驳回 2-审核通过 3-确认收货 4-完成退款
					},
				}).then((res) => {
					if (res.code == 200) {
						this.setView();
						this.$message({
							message: res.msg,
							type: 'success'
						})
					} else {
						alertErr(res.msg)
					}
				});
			}).catch(() => {

			});
		},



		confirmAuditSubmit() {
			this.setView()
		},

		select_refundStatus_onchange() {
			this.initQuery()
		}
	},
};
</script>

<style scoped lang="less">
// /deep/ .el-table table {
//   width: 100% !important;

//   thead {
//     th.el-table__cell {
//       background: #f8f8f8;
//       color: #000;
//     }
//   }
// }


.page-table-ctx-wrap {
	background: #fff;
	padding: 20px;
	border-radius: 6px;
}

// 新增
.control-box {
	.flex-between();

	.control-left {
		.flex();

		.control-item {
			margin-right: 10px;
		}
	}

	.control-right {
		.flex();

		.action-item {
			margin-left: 10px;
		}
	}
}

.table-view {
	margin-top: 20px;
	margin-bottom: 20px;
}


// 表格工具栏
.table-util {
	.flex-between();

	.util-left {
		.flex();
		min-width: 100px;

		.util-items {
			.flex();

			.item {
				margin-right: 10px;
			}
		}
	}

	.util-right {}
}


.tab-box {
	margin: 20px 0;
}
</style>